# -*- coding: UTF-8 -*-
from db_connection import *
import json,traceback
class sqlHelper:
    @classmethod
    def selectBool(self,sql,params=None):
        with getConnection() as db:
            try:
                db.cur.execute(sql,params)
                info=db.cur.fetchmany()
                return info
            except Exception,e: 
                print 'Mysql Error->'+sql
                traceback.print_exc()
                return False

    @classmethod
    def selectOne(self,sql,params=None):
        with getConnection() as db:
            try:
                n=db.cur.execute(sql,params)
                info=db.cur.fetchmany(n)
                if info:
                    return info[0]
                return None
            except Exception,e:
                print 'Mysql Error->'+sql
                traceback.print_exc()
                return False
    @classmethod
    def selectAll(self,sql,params=None):
        with getConnection() as db:
            try:
                n=db.cur.execute(sql,params)
                info=db.cur.fetchmany(n)
                return info
            except Exception,e:
                print 'Mysql Error->'+sql
                traceback.print_exc()
                return False

    @classmethod
    def update(self,sql,params):
        with getConnection() as db:
            try:
                res=db.cur.execute(sql,params)
                db.conn.commit()
                return res
            except Exception,e:
                print 'Mysql Error->'+sql
                traceback.print_exc()
                return False
